package com.wang;

import lombok.Builder;
import lombok.ToString;

/**
 * @description: json响应数据封装
 * @author: wp
 * @date: 2019/11/4 14:46
 **/
@ToString
@Builder
public class ResponseJson {

    private static final Integer SUCCESS = 0;
    private static final Integer ERROR = 500;
    private static final Integer FAIL = -1;
    private static final String SUCCESS_MSG = "操作成功";
    private static final String FAIL_MSG = "操作失败";
    private static final String ERROR_MSG = "系统异常";

    private Integer code;

    private String msg;

    private Object obj;

    private int total;

    public static ResponseJson ok() {
        return ResponseJson.builder().code(SUCCESS).msg(SUCCESS_MSG).build();
    }

    public static ResponseJson ok(Object obj) {
        return ResponseJson.builder().code(SUCCESS).msg(SUCCESS_MSG).obj(obj).build();
    }

    public static ResponseJson ok(Object obj, int total) {
        return ResponseJson.builder().code(SUCCESS).msg(SUCCESS_MSG).obj(obj).total(total).build();
    }

    /*public static ResponeJson fail() {
        return ResponeJson.builder().code(FAIL).msg(FAIL_MSG).build();
    }*/

    public static ResponseJson fail(String msg) {
        return ResponseJson.builder().code(FAIL).msg(msg).build();
    }

    public static ResponseJson error(String msg) {
        return ResponseJson.builder().code(ERROR).msg(msg).build();
    }

    public static ResponseJson error() {
        return ResponseJson.builder().code(ERROR).msg(ERROR_MSG).build();
    }
}
